import requests
import execjs
import json

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
    "Refer": "https://music.163.com/"
}

with open('AllJs/网易云.js','r',encoding='utf-8') as f:
    js_code = f.read()

js_compile = execjs.compile(js_code)
song_id = 1429237296
t = {"ids": f"[{song_id}]", "level": "standard", "encodeType": "aac", "csrf_token": ""}

x1 = json.dumps(t)
x2 = '010001'
x3 = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
x4 = '0CoJUm6Qyw8W8jud'

ret = js_compile.call("d", x1, x2, x3, x4)
print(ret)

data = {
    "params": ret["encText"],
    "encSecKey": ret["encSecKey"]
}
url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token='

res = requests.post(url, data=data, headers=headers)
print(res.text)